// 评论列表组件
import React from 'react';
import classNames from 'classnames';
// 导入图片
import avatar from '../avatar.jpg';

export class CommentList extends React.Component {
  render() {
    return (
      // 评论列表区
      <div className="comment-list">
        {this.props.list.map((item) => {
          return (
            <div key={item.id} className="comment-item">
              <div>
                <img className="user-head" src={avatar} alt="头像" />
              </div>

              <div className="comment">
                <div className="user">{item.author}</div>
                <p className="text">{item.comment}</p>
                <div className="info">
                  <span className="time">{item.time}</span>
                  <span
                    className={classNames({
                      like: true,
                      liked: item.attitude === 1,
                    })}
                    onClick={() =>
                      this.props.changeAttitude(
                        item.id,
                        item.attitude === 1 ? 0 : 1
                      )
                    }
                  >
                    <i className="icon" />
                  </span>
                  <span
                    className={classNames({
                      hate: true,
                      hated: item.attitude === -1,
                    })}
                    onClick={() =>
                      this.props.changeAttitude(
                        item.id,
                        item.attitude === -1 ? 0 : -1
                      )
                    }
                  >
                    <i className="icon" />
                  </span>
                  <span
                    className="btn-hover"
                    onClick={() => this.props.delComment(item.id)}
                  >
                    删除
                  </span>
                </div>
              </div>
            </div>
          );
        })}
      </div>
    );
  }
}

export default CommentList;
